package org.kl.bf.entity.basic;

import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.kl.bf.entity.AuditableEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;

//JPA标识
@Entity
@Table(name = "basic_menu")
public class Menu extends AuditableEntity {

	private static final long serialVersionUID = 4316817356569526687L;
	private String menuName;
	private String menuUrl;
	private String menuTips;
	private String menuTarget;
	private Integer displayOrder;
	private String controller;
	private String iconClass;
	private String otherRights;
	private String menuParentId;
	private String rootId;
	private Set<Function> functions;
	/**
	 * 子菜单集
	 */
	private List<Menu> childMenuList;
	/**
	 * 父菜单集
	 */
	private List<Menu> parentMenuList;
	/**
	 * 所在层数
	 */
	private int layer;
	/**
	 * 父菜单名称
	 */
	private String parentMenuName;
	/**
	 * 生成JSON
	 */
	private Set<Function> functionForJson;

	public Menu() {
	}

	public Menu(String id) {
		this.id = id;
	}

	@JsonIgnore
	@OneToMany(mappedBy = "menu")
	@OrderBy(value = "functionNo ASC")
	public Set<Function> getFunctions() {
		return functions;
	}

	public void setFunctions(Set<Function> functions) {
		this.functions = functions;
	}

	public String getMenuName() {
		return menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	public String getMenuUrl() {
		return menuUrl;
	}

	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}

	public String getMenuTips() {
		return menuTips;
	}

	public void setMenuTips(String menuTips) {
		if (StringUtils.isEmpty(menuTips))
			menuTips = this.getMenuName();
		this.menuTips = menuTips;
	}

	public String getMenuTarget() {
		return menuTarget;
	}

	public void setMenuTarget(String menuTarget) {
		this.menuTarget = menuTarget;
	}

	public Integer getDisplayOrder() {
		return displayOrder;
	}

	public void setDisplayOrder(Integer displayOrder) {
		this.displayOrder = displayOrder;
	}

	public String getController() {
		return controller;
	}

	public void setController(String controller) {
		this.controller = controller;
	}

	public String getIconClass() {
		return iconClass;
	}

	public void setIconClass(String iconClass) {
		this.iconClass = iconClass;
	}

	public String getOtherRights() {
		return otherRights;
	}

	public void setOtherRights(String otherRights) {
		this.otherRights = otherRights;
	}

	public String getMenuParentId() {
		return menuParentId;
	}

	public void setMenuParentId(String menuParentId) {
		if (StringUtils.isBlank(menuParentId)) {
			this.menuParentId = null;
		} else {
			this.menuParentId = menuParentId;
		}
	}

	public String getRootId() {
		return rootId;
	}

	public void setRootId(String rootId) {
		this.rootId = rootId;
	}

	@Transient
	public List<Menu> getChildMenuList() {
		return childMenuList;
	}

	public void setChildMenuList(List<Menu> childMenuList) {
		this.childMenuList = childMenuList;
	}

	@Transient
	public List<Menu> getParentMenuList() {
		return parentMenuList;
	}

	public void setParentMenuList(List<Menu> parentMenuList) {
		this.parentMenuList = parentMenuList;
	}

	@Transient
	public int getLayer() {
		return layer;
	}

	public void setLayer(int layer) {
		this.layer = layer;
	}

	@Transient
	public String getParentMenuName() {
		return parentMenuName;
	}

	public void setParentMenuName(String parentMenuName) {
		this.parentMenuName = parentMenuName;
	}

	@Transient
	public Set<Function> getFunctionForJson() {
		return functionForJson;
	}

	public void setFunctionForJson(Set<Function> functionForJson) {
		this.functionForJson = functionForJson;
	}

}
